package a51qindian.com.comprehensive.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.li.utils.TransformUtil;
import com.li.widget.DoubleTextView;

import java.util.List;

import a51qindian.com.comprehensive.R;
import a51qindian.com.comprehensive.model.CouponInfo;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Author: Li
 * Date: 2017/10/16 0016
 * Description: 优惠券列表适配器
 */

public class CouponAdapter extends RecyclerView.Adapter<CouponAdapter.CouponHolder> {


    public void setCouponInfoList(List<CouponInfo> couponInfoList) {
        mCouponInfoList = couponInfoList;
        notifyDataSetChanged();
    }

    private List<CouponInfo> mCouponInfoList;
    private LayoutInflater mInflater;

    public CouponAdapter(Context context) {
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public CouponHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_coupon, parent, false);
        return new CouponHolder(view);
    }

    @Override
    public void onBindViewHolder(CouponHolder holder, int position) {
        CouponInfo couponInfo = mCouponInfoList.get(position);
        holder.mTxtName.setTxtRight(couponInfo.getUse_name());
        holder.mTxtMoney.setTxtRight(couponInfo.getUse_money());
        holder.mTxtTime.setTxtRight(TransformUtil.timeFormat(couponInfo.getUse_time()));
    }

    @Override
    public int getItemCount() {
        return mCouponInfoList == null ? 0 : mCouponInfoList.size();
    }

    static class CouponHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.txt_name)
        DoubleTextView mTxtName;
        @BindView(R.id.txt_money)
        DoubleTextView mTxtMoney;
        @BindView(R.id.txt_time)
        DoubleTextView mTxtTime;

        public CouponHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
